package leetcode;

import org.junit.Test;

import java.util.HashMap;

/**
 * @author cino
 * justCode
 */
public class leetcode205 {

    @Test
    public void test(){
        System.out.println(isIsomorphic("paper", "title"));
    }

    public boolean isIsomorphic(String s, String t) {
        HashMap<Character, Character> map = new HashMap<>();
        int len = s.length();
        char[] c1 = s.toCharArray();
        char[] c2 = t.toCharArray();
        if (len != t.length())return false;
        for (int i = 0;i<len;i++){
            if (!map.containsKey(c1[i])){
                if (map.containsValue(c2[i])){
                    return false;
                }
                map.put(c1[i],c2[i]);
            }else if (!map.get(c1[i]).equals(c2[i])){
                return false;
            }
        }
        return true;
    }
}
